package cn.kgc.tangcco.anyang.aop.b_dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class UserServiceImplProxy {
	private UserService target;

	public UserServiceImplProxy() {
		this(new UserServiceImpl());
	}

	public UserServiceImplProxy(UserService target) {
		this.target = target;
	}

	public Object getProxyInstance() {
		return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(),
				new InvocationHandler() {

					@Override
					public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
						System.out.println("开启事务");
						Object returnValue = method.invoke(target, args);
						System.out.println("提交事务");
						return returnValue;
					}
				});
	}

}
